package cn.zqy.demo3.day01.Jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo04JdbcDelete {
    public static void main(String[] args) {
    Connection conn = null;
    Statement statement = null;
    try {
        //1. 注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接对象
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/heima",
                "root", "123456");
        //3.获取执行sql对象
        statement = conn.createStatement();
        //4.定义sql
        String sql = "delete  from account where id=3";
        //5.执行sql
        int num = statement.executeUpdate(sql);
        //6.处理结果
        if (num > 0) {
            System.out.println("删除成功！！");
        } else {
            System.out.println("删除失败罗。。。");
        }
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    } finally {
        //7.释放资源
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

}
